home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / tmp / pqcomm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.4 KB  |  124 lines

  1. /*
  2.  * comm.h -- parameters for the communication module
  3.  *
  4.  * $Header: /private/postgres/src/lib/H/tmp/RCS/pqcomm.h,v 1.3 1991/02/28 10:49:50 mer Exp $
  5.  *
  6.  * Some of this should move to pqlib.h
  7.  */
  8.  
  9. #include "catalog/pg_user.h"
  10. /*
  11.  * startup msg paramters: path length, argument string length
  12.  */
  13. #define PATH_SIZE    64
  14. #define ARGV_SIZE    64
  15.  
  16. /*
  17.  * For sequenced packet, this is fixed to 2K by UDP protocol.
  18.  * For the stream implementation, it depends only on available
  19.  *    buffering.
  20.  */
  21. #define MAX_PACKET_SIZE    (2*1024)
  22.  
  23. typedef enum MsgType {
  24.   ACK_MSG = 0,        /* acknowledge a message */
  25.   ERROR_MSG=1,        /* error response to client from server */
  26.   RESET_MSG=2,        /* client must reset connection */
  27.   PRINT_MSG=3,        /* tuples for client from server */
  28.   NET_ERROR=4,        /* error in net system call */
  29.   FUNCTION_MSG=5,    /* fastpath call (unused) */
  30.   QUERY_MSG=6,        /* client query to server */
  31.  
  32.   STARTUP_MSG=7,    /* initialize a connection with a backend */
  33.   DUPLICATE_MSG=8,/* duplicate message arrived (errors msg only) */
  34.   INVALID_MSG=9,    /* for some control functions */
  35. } MsgType;
  36.  
  37. typedef char *Addr;
  38. typedef int SeqNo;    /* (seq pack protocol) sequence numbers */
  39. typedef int ConnId;    /* (seq pack protocol) connection ids */
  40. typedef int PacketLen;    /* packet length */
  41.  
  42. typedef struct PacketHdr {
  43.   SeqNo        seqno;
  44.   PacketLen    len;
  45.   ConnId    connId;
  46.   MsgType    type;
  47. } PacketHdr;
  48.  
  49. typedef struct StartupPacket {
  50.   PacketHdr    hdr;
  51.   char        database[PATH_SIZE];    /* database name */
  52.   char        user[USER_NAMESIZE];    /* user name */
  53.   char        options[ARGV_SIZE];    /* possible additional args */
  54.   char        execFile[ARGV_SIZE];    /*  possible backend to use */
  55.   char        tty[PATH_SIZE];        /*  possible tty for debug output */
  56. } StartupPacket;
  57.  
  58. /* amount of available data in a packet buffer */
  59. #define MESSAGE_SIZE    (MAX_PACKET_SIZE - sizeof(PacketHdr))
  60.  
  61. typedef struct MsgPacket {
  62.   PacketHdr    hdr;
  63.   char        message[MESSAGE_SIZE];
  64. } MsgPacket;
  65.  
  66. /* I/O can be blocking or non-blocking */
  67. #define BLOCKING     (FALSE)
  68. #define NON_BLOCKING    (TRUE)
  69.  
  70. /* buffers for incoming packets */
  71. typedef int PacketBufId;
  72.  
  73. /*
  74.  * Watch out if PacketBufId changes size.  Some compilers
  75.  * will allocate padding.  PacketBuf should be exactly
  76.  * MESSAGE_SIZE big.  I have an assert statement in InitComm
  77.  */
  78. typedef struct PacketBufHdr {
  79.   PacketBufId    id,prev,next;
  80. } PacketBufHdr;
  81.  
  82. typedef struct PacketBuf {
  83.   PacketBufId    id,prev,next;
  84.   char         data[MESSAGE_SIZE - sizeof(PacketBufHdr)];
  85. } PacketBuf;
  86.  
  87.  
  88. /*
  89.  * socket descriptor port 
  90.  */
  91. typedef struct Port {
  92.   int            sock;    /* file descriptor */
  93.   int            mask;    /* select mask */
  94.   int           nBytes;    /* nBytes read in so far */
  95.   struct sockaddr_in    addr;    /* addr of sender */
  96.   PacketBufId        id;    /* id of packet buf currently in use */
  97.   PacketBuf        buf;    /* stream implementation (curr pack buf) */
  98. } Port;
  99.  
  100. /*
  101.  * Connection to client
  102.  */
  103. typedef struct Connection {
  104.   struct sockaddr_in    addr;    /* addr of client */
  105.   SeqNo            seqno;    /* next expected sequence number */
  106.   ConnId        id,prev,next;      /* connection queue links. */
  107.   PacketBufId        packSend,packRecv; /* send/receive packet bufs */
  108.   long            lastUse;/* last recieve time for Gbg Collection */
  109.   int            uid;    /* unique id (generation number) */
  110. } Connection;
  111.  
  112. /* invalid socket descriptor */
  113. #define INVALID_SOCK    (-1)
  114.  
  115. #define INVALID_ID (-1)
  116. #define MAX_CONNECTIONS    10
  117. #define N_PACK_BUFS    20
  118.  
  119. /* no multi-packet messages yet */
  120. #define MAX_PACKET_BACKLOG    1
  121.  
  122. #define INITIAL_SEQNO        1
  123. #define    DEFAULT_STRING        ""
  124.